/*
c/s模式，客户端实现
*/
#include "ros/ros.h"
#include "plumbing_c_s/AddInts.h"

int main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");
    if (argc != 3)
    {
        ROS_INFO("提交的参数个数不正确。");
        return 1;
    }
    ros::init(argc, argv, "client");
    ros::NodeHandle nh = ros::NodeHandle();
    // 创建客户端实例化对象
    ros::ServiceClient client = nh.serviceClient<plumbing_c_s::AddInts>("addInts");
    // 若服务端还没有启动，则等待。有下面两种方式
    // ros::service::waitForService("addInts");
    client.waitForExistence();
    // 填充请求的数据
    plumbing_c_s::AddInts ai;
    ai.request.num1 = atoi(argv[1]);
    ai.request.num2 = atoi(argv[2]);
    bool res = client.call(ai);
    if (res)
    {
        ROS_INFO("返回成功！");
        ROS_INFO("返回结果为:%d", ai.response.sum);
    }
    else
    {
        ROS_INFO("返回失败！");
    }
    return 0;
}
